package com.jshan.blog.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jshan.blog.annotation.OperationLog;
import com.jshan.blog.base.admin.dto.AccInfoDto;
import com.jshan.blog.base.admin.entity.SysDict;
import com.jshan.blog.converts.SysDictConvert;
import com.jshan.blog.enums.BizCodeEnums;
import com.jshan.blog.result.Result;
import com.jshan.blog.service.SysDictService;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/accAndTag")
public class TagAndAccountController {

    @Resource
    private SysDictService sysDictService;


    @OperationLog(value = "根据标签ID查询标签列表", operationType = "查询")
    @GetMapping("/getAccountInfoList/{tagId}")
    @SaIgnore
    public Result getAccountInfoList(@PathVariable("tagId") Integer tagId){
        List<SysDict> list = sysDictService.list(new LambdaQueryWrapper<SysDict>().eq(SysDict::getSysDictTypeId, tagId));
        if (CollectionUtils.isNotEmpty(list)) {
          List<AccInfoDto>  accInfoDtoList =SysDictConvert.INSTANCE.DictListConvertDtoList(list);
          return Result.ok(accInfoDtoList);
        }
        return Result.fail(BizCodeEnums.FAILE.getCode(), "获取用户信息失败！");
    }

}
